package com.home.free.fectory.user;

import com.home.free.entity.User;
import com.home.free.entity.UserStatusEnum;
import com.home.free.util.DateUtil;
import com.home.free.vo.user.UserVo;

import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * 组装返回用户对象的返回
 * @author gaotianjie
 */
public class BuildUserVo implements Serializable  {
    /**
     * 组装返回用户返回页面的数据
     *
     * @param userList
     * @return
     */
    public static List<UserVo> buildUserVoPage(List<User> userList) {
        List<UserVo> userVoList = new ArrayList<>();
        for (User user :  userList) {
            UserVo userVo = new UserVo();
            userVo.setId(user.getId());
            userVo.setEmail(user.getEmail());
            userVo.setUserName(user.getUserName());
            userVo.setBirthdayTimeStr(DateUtil.timeToString(Long.valueOf(user.getRegisterTime()) * 1000));
            userVo.setUserStatusStr(UserStatusEnum.getName(user.getUserStatus()));
            userVoList.add(userVo);
        }

        return userVoList;
    }


    public static User buildUserVoToUser(UserVo userVo) {
        User user = new User();
        try {
            user.setBirthdayTime(DateUtil.stringToTime(userVo.getBirthdayTimeStr()));
        } catch (ParseException p) {

        }

        user.setRegisterTime(DateUtil.getSecondTime());
        user.setcT(DateUtil.getMilliSecondTime());
        user.setuT(DateUtil.getMilliSecondTime());
        user.setUserName(userVo.getUserName());
        user.setUserStatus(UserStatusEnum.EXAMINE.getId());

        return user;
    }
}
